package org.ceteca.explica.core.partners;

import java.io.Serializable;
import java.math.BigDecimal;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;


/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class RappelIntervalOT extends BaseVO implements Serializable {


	
	
	private static final long serialVersionUID = 1L;

	
	private long idRappelInterval;
	private RappelTypeOT rappelType;
	private BigDecimal lowerLimit;
	private BigDecimal upperLimit;
	private double disccountRate;
	
	private Integer version=new Integer(0);
	
	

	public RappelIntervalOT() {
		super();

	}


	
	
	
	

	public long getIdRappelInterval() {
		return idRappelInterval;
	}

	public void setIdRappelInterval(long idRappelInterval) {
		this.idRappelInterval = idRappelInterval;
	}

	public RappelTypeOT getRappelType() {
		return rappelType;
	}

	public void setRappelType(RappelTypeOT rappelType) {
		this.rappelType = rappelType;
	}

	public String getRappelTypeName(){
		String result=null;
		if (rappelType!=null)
			result=rappelType.getDescription();
		return result;
	}
	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idRappelInterval == id.longValue();
	}

	

	@Override
	public String toString() {
		
		
		return getInternalValue();
			
	
	}

	@Override
	public String getEntityId() {
	
		return InterfacePartners.EXPLICA_ENTITY_RAPPELINTERVAL_ID;
	}

	@Override
	public long getInternalId() {

		return this.idRappelInterval;
	}

	@Override
	public String getInternalValue() {

		StringBuilder result= new StringBuilder();
			result.append(getRappelTypeName());
			result.append("/");
			result.append(getLowerLimit());
			result.append("/");
			result.append(getUpperLimit());
			result.append("/");
			result.append(getDisccountRate());
			return result.toString();
	}

	public Integer getVersion() {
		return version;
	}







	public void setVersion(Integer version) {
		this.version = version;
	}







	public BigDecimal getLowerLimit() {
		return lowerLimit;
	}







	public void setLowerLimit(BigDecimal lowerLimit) {
		this.lowerLimit = lowerLimit;
	}







	public BigDecimal getUpperLimit() {
		return upperLimit;
	}







	public void setUpperLimit(BigDecimal upperLimit) {
		this.upperLimit = upperLimit;
	}







	public double getDisccountRate() {
		return disccountRate;
	}







	public void setDisccountRate(double disccountRate) {
		this.disccountRate = disccountRate;
	}




/*


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(disccountRate);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result
				+ ((lowerLimit == null) ? 0 : lowerLimit.hashCode());
		result = prime * result
				+ ((rappelType == null) ? 0 : rappelType.hashCode());
		result = prime * result
				+ ((upperLimit == null) ? 0 : upperLimit.hashCode());
		return result;
	}







	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj==null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RappelIntervalOT other = (RappelIntervalOT) obj;
		if (Double.doubleToLongBits(disccountRate) != Double
				.doubleToLongBits(other.disccountRate))
			return false;
		if (lowerLimit == null) {
			if (other.lowerLimit != null)
				return false;
		} else if (!lowerLimit.equals(other.lowerLimit))
			return false;
		if (rappelType == null) {
			if (other.rappelType != null)
				return false;
		} else if (!rappelType.equals(other.rappelType))
			return false;
		if (upperLimit == null) {
			if (other.upperLimit != null)
				return false;
		} else if (!upperLimit.equals(other.upperLimit))
			return false;
		return true;
	}


*/


    @Override
    public int hashCode() {
        final HashCodeBuilder hcb = new HashCodeBuilder();
        hcb.append(lowerLimit);
        hcb.append(upperLimit);
        hcb.append(rappelType);
        hcb.append(this.disccountRate);
        return hcb.toHashCode();
    }

    
    
    @Override
    public boolean equals(Object obj) {
        boolean isEquals = false;
        try {
            final RappelIntervalOT other = (RappelIntervalOT)obj;
            final EqualsBuilder eqb = new EqualsBuilder();
            eqb.append(getRappelType(), other.getRappelType());
            eqb.append(getLowerLimit(), other.getLowerLimit());
            eqb.append(getUpperLimit(), other.getUpperLimit());
            eqb.append(getDisccountRate(), other.getDisccountRate());
            isEquals = eqb.isEquals();

        } catch (Exception e) {
            isEquals = false;
        }

        return isEquals;
    }







	
	

}
